<style >
  table.formTable {
    font-family: verdana, arial, sans-serif;
    font-size: 0.875rem;
    color: #333333;
    border-width: 0px;
    border-color: #dcdfe6;
    border-collapse: collapse;
    width: 100%;
  }

  table.formTable td {
    border-width: 0px;
    padding: 20px;
    border-style: solid;
    border-color: #dcdfe6;
    background-color: #ffffff;
    padding:2px;
    text-align: center;
  }

  table.formTable td:first-child {
    width: 100px;
    text-align: right;
  }

  table.formTable td:last-child {
  	 color: #E6A23C; 
  }
  
      #tableIconForBizStylePolygon + .layui-table-view .layui-table-body tbody > tr > td {
        padding: 0;
    }

    #tableIconForBizStylePolygon + .layui-table-view .layui-table-body tbody > tr > td > .layui-table-cell {
        height: 60px;
        line-height: 60px;
    }

    .tdImg {
        width: 35px;
        height:35px;
        max-width: none;
        cursor: pointer;
    }

    .layui-table-view {
        margin: 0;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar" id="tbToolBar">
                <div class="layui-form-item">
					<div class="layui-inline">
						<button id="btnAddBizStylePolygon" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>新增</button>
					</div>
                    <div class="layui-inline" style="float: right;margin-right: 0px;">
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<label class="layui-form-label w-auto">名称</label>
							<div class="layui-input-inline mr0">
								<input name="name" class="layui-input" type="text" placeholder="请输入名称"/>
							</div>
						</div>
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<button class="layui-btn icon-btn" lay-filter="formSubSearchBizStylePolygon" lay-submit>
								<i class="layui-icon">&#xe615;</i>查询
							</button>
						</div>					
					</div>
				</div>
				<table class="layui-table" id="tableBizStylePolygon" lay-filter="tableBizStylePolygon"></table>
			</div>
		</div>
	</div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="tableBarBizStylePolygon">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="copy">复制</a>
</script>
<!-- 表格状态列 -->
<script type="text/html" id="tableStateBizStylePolygon">
#[[  {{#  if(d.status === '1'){ }}
    <span style="color: #23aa2e;">正常</span>
  {{#  } else { }}
	<span style="color: #ff0000;">禁止</span>
  {{#  } }}
]]#
</script>


<!-- 表单弹窗-->
<script type="text/html" id="modelBizStylePolygon"> 
    <form id="modelBizStylePolygonForm" lay-filter="modelBizStylePolygonForm" class="layui-form model-form" style="padding: 5px;">
        <input name="id" type="hidden"  />
		<table class="formTable">
			<tr>
				<td>名称</td>
				<td colspan="3" style="text-align: left;">
                	<input name="name"  placeholder="请输入名称" type="text" class="layui-input" lay-verType="tips" lay-verify="required" required/>
                </td>
			</tr>
			<tr>
				<td>标识</td>
				<td colspan="3" style="text-align: left;">
                	<input name="code"  placeholder="请输入标识" type="text" class="layui-input" />
                </td>
			</tr>
			<tr>
				<td>填充</td>
				<td colspan="3" style="text-align: left;">
			      <select name="fill" lay-filter="fill" >
			        <option value="0" >否</option>
			        <option value="1" >是</option>
			      </select>
                </td>
			</tr>	
			<tr>
				<td>材质类型</td>
				<td colspan="3" style="text-align: left;">
			      <select name="material" lay-filter="material" >
			        <option value="color"  >颜色</option>
			      </select>
                </td>
			</tr>					
			<tr >
				<td>颜色</td>
				<td colspan="3" style="text-align: left;">
					<input type="hidden" name="color"  id="color-input">
					<div id="color"></div>			      
                </td>
			</tr>				
			<tr>
				<td>显示轮廓</td>
				<td colspan="3" style="text-align: left;">
			      <select name="outline" lay-filter="outline" >
			        <option value="0"  >隐藏</option>
			        <option value="1" >显示</option>
			      </select>
                </td>
			</tr>			
			<tr id="outlineColor-tr" style="display: none;">
				<td>轮廓颜色</td>
				<td colspan="3" style="text-align: left;">
					<input type="hidden" name="outlineColor"  id="outlineColor-input">
					<div id="outlineColor"></div>			      
                </td>
			</tr>
			<tr id="outlineWidth-tr" style="display: none;">
				<td>轮廓粗细</td>
				<td colspan="3" style="text-align: left;">
                	<input name="outlineWidth"  placeholder="请输入粗细值" type="text" class="layui-input" lay-verType="tips" />
                </td>
			</tr>
			
			<tr>
				<td>可视范围</td>
				<td >
                	<input name="distanceDisplayConditionX"  placeholder="请输入x" value='0' type="number" class="layui-input" lay-verType="tips"  />
                </td>
				<td >
                	<input name="distanceDisplayConditionY"  placeholder="请输入y" value="50000" type="number" class="layui-input" lay-verType="tips" />
                </td>                
			</tr>
			<tr>
				<td>启用高度</td>
				<td colspan="3" style="text-align: left;">
			      <select name="perPositionHeight" lay-filter="perPositionHeight" >
			        <option value="0"  >否</option>
			        <option value="1" >是</option>
			      </select>
                </td>
			</tr>		
			<tr>
				<td>高度</td>
				<td colspan="3" style="text-align: left;">
                	<input name="height"  placeholder="请输入高度" type="text" class="layui-input" lay-verType="tips" />
                </td>
			</tr>	
			<tr>
				<td>高度参照</td>
				<td colspan="3" style="text-align: left;">
			      <select name="heightReference" lay-filter="heightReference" >
			        <option value="0" >NONE</option>
			        <option value="1" >CLAMP_TO_GROUND</option>
			        <option value="2" >RELATIVE_TO_GROUND</option>
			      </select>
                </td>
			</tr>	
			<tr>
				<td>凸出高度</td>
				<td colspan="3" style="text-align: left;">
                	<input name="extrudedHeight"  placeholder="请输入" type="text" class="layui-input" lay-verType="tips" />
                </td>
			</tr>
			<tr>
				<td>凸出高度参照</td>
				<td colspan="3" style="text-align: left;">
			      <select name="extrudedHeightReference" lay-filter="extrudedHeightReference" >
			        <option value="0"  >NONE</option>
			        <option value="1" >CLAMP_TO_GROUND</option>
			        <option value="2" >RELATIVE_TO_GROUND</option>
			      </select>
                </td>
			</tr>
			<tr>
				<td>纹理旋转</td>
				<td colspan="3" style="text-align: left;">
                	<input name="stRotation"  placeholder="请输入" type="text" class="layui-input" lay-verType="tips" />
                </td>
			</tr>
			<tr>
				<td>显示顶部</td>
				<td colspan="3" style="text-align: left;">
			      <select name="closeTop" lay-filter="closeTop" >
			        <option value="0"  >否</option>
			        <option value="1" >是</option>
			      </select>
                </td>
			</tr>
			<tr>
				<td>显示底部</td>
				<td colspan="3" style="text-align: left;">
			      <select name="closeBottom" lay-filter="closeBottom" >
			        <option value="0"  >否</option>
			        <option value="1" >是</option>
			      </select>
                </td>
			</tr>			

			<tr>
				<td>显示分类</td>
				<td colspan="3" style="text-align: left;">
			      <select name="classificationType" lay-filter="classificationType" >
			        <option value="0" >底图和模型</option>
			        <option value="1" >底图</option>
					<option value="2" >模型</option>
			      </select>
                </td>
			</tr>			
						
			<tr>
				<td>是否可用</td>
				<td colspan="3" style="text-align: left;">
			      <select name="enabled" lay-filter="enabled" >
 					<option value="1" >启用</option>
			        <option value="0"  >禁用</option>
			      </select>
                </td>
			</tr>
			<tr>
				<td>序号</td>
				<td colspan="3">
                <input name="sort" placeholder="请输入序号" type="number"  value='0'   class="layui-input"  
                       lay-verType="tips" lay-verify="required|number" required/>
                </td>
			</tr>
			<tr>
				<td colspan="4">
		            <button class="layui-btn" lay-filter="modelSubmitBizStylePolygonForm" lay-submit>保存</button>
                </td>
			</tr>												
		</table>    
    </form>
</script>


<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin', 'config','colorpicker'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var config = layui.config;
        var colorpicker = layui.colorpicker;
        // 渲染表格
        var insTb = table.render({
            elem: '#tableBizStylePolygon',
            url: '#(ctx)/biz/style/polygon/listData', 
            page: true,
            toolbar: false,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号'},
                {field: 'name', sort: false, title: '名称'},
                {
                    field: 'createTime', sort: false, templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, title: '创建时间'
                },
				{field: 'status', sort: false, templet: '#tableStateBizStylePolygon', title: '状态', align: 'center'},
                {align: 'left', toolbar: '#tableBarBizStylePolygon', title: '操作'}
            ]],
        });

        // 添加
		$('#btnAddBizStylePolygon').click(function () {
			 showEditModel();
		});

        // 搜索
        form.on('submit(formSubSearchBizStylePolygon)', function (data) {
            insTb.reload({where: data.field}, 'data');
        });

        // 工具条点击事件
        table.on('tool(tableBizStylePolygon)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') { // 修改
            	showEditModel(data);
            } else if (layEvent === 'del') { // 删除
                doDel(data.id, data.name);
            }
            else if (layEvent === 'copy') { // 删除
            	copy(data.id, data.name);
            }
            
        });

        // 删除
        function doDel(id, name) {
            layer.confirm('确定要删除“【<span style="color:red;">' + name + '</span>】”吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('biz/style/polygon/delete', {
                    id: id
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.message, {icon: 1});
                        insTb.reload({}, 'data');
                    } else {
                        layer.msg(res.message, {icon: 2});
                    }
                }, 'get');
            });
        }
        
        function copy(id, name) {
            layer.confirm('确定要克隆“【<span style="color:red;">' + name + '</span>】”吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('biz/style/polygon/copy', {
                    id: id
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.message, {icon: 1});
                        insTb.reload({}, 'data');
                    } else {
                        layer.msg(res.message, {icon: 2});
                    }
                }, 'get');
            });
        }


        // 显示表单弹窗
        function showEditModel(data) {
            layer.open({
                type: 1,
                shade: 0.3,
                offset: 't'	,
                title: (data ? '修改' : '添加') + '',
                area:'500px',
                resize :false,
                content: $('#modelBizStylePolygon').html(),
                success: function (layero, dIndex) {
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    form.val('modelBizStylePolygonForm', data);  // 回显数据

                	colorpicker.render({//间隔颜色
                		elem: '#color',
                		color: (data&&data.color)?data.color:null,
                		format: 'rgb',
                		predefine: true,
                		alpha: true,
                		done: function(color) {
                			$('#color-input').val(color); //向隐藏域赋值
                			color || this.change(color); //清空时执行 change
                		},
                		change: function(color) {}
                	});
                	
                	colorpicker.render({//间隔颜色
                		elem: '#outlineColor',
                		color: (data&&data.outlineColor)?data.outlineColor:null,
                		format: 'rgb',
                		predefine: true,
                		alpha: true,
                		done: function(color) {
                			$('#outlineColor-input').val(color); //向隐藏域赋值
                			color || this.change(color); //清空时执行 change
                		},
                		change: function(color) {}
                	});	
                	
                	
                	form.on('select(outline)', function(data){
                		if("1"==data.value){
                			showForOutline();
                		}
                		else{
                			hideForOutline();
                		}
                		form.render();
                	})
                	
               		if(data&& data.outline=='1')
						showForOutline();
					else
						hideForOutline();
                    
                	
    			    form.on('submit(modelSubmitBizStylePolygonForm)', function (data) {
    			        layer.load(2);
    			        var formData={}; 
    			        for(var key in data.field){
    			        	formData['bizStylePolygon.'+key]=data.field[key];
    			        }
                        admin.req("biz/style/polygon/save",formData, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.close(dIndex);
                                layer.msg(res.message, {icon: 1});
                                insTb.reload({}, 'data');
                            } else {
                                layer.msg(res.message, {icon: 2});
                            }
                        }, 'get');
    			        return false;
    			    });
    			    form.render(); 
                },
                end:function(){
                }
            });
        }

    });
    
    
	function showForOutline(){
		$('#outlineColor-tr').css('display','');
		$('#outlineWidth-tr').css('display','');
	}
	function hideForOutline(){
		$('#outlineColor-tr').css('display','none');
		$('#outlineWidth-tr').css('display','none');
	}    
</script>
